﻿jQuery.fn.tabbededitor = function(options)
{
    var defaults =
    {
        length: -1,
        columns: 90,
        rows: 18,
        width: -1,
        height: -1,
    };

    var $ = jQuery;
	var settings = $.extend({}, defaults, options);
    var target = $(this);
    $("#wmdTabs").tabs();
	var puptext = $('#pupedit-text');
    puptext.text(target.val());
	puptext.wmd({'preview': "wmd-preview", button_bar:"wmd-button-bar"});
    if (settings.width == -1) settings.width = settings.columns * 9;
    if (settings.height == -1) settings.height = settings.rows * 15;

//    $('#tabs-edit').css({ 'width': settings.width, 'height': settings.height });
///    $('#tabs-preview').css({ 'width': settings.width, 'height': settings.height });
//    $('#wmd-preview').css({ 'width': settings.width, 'height': settings.height });
//    $('#tabs-help').css({ 'width': settings.width, 'height': settings.height });

    $('#tabs-preview').css({ 'width': '98%', 'height': settings.height });
    $('#wmd-preview').css({ 'width': '95%', 'height': settings.height });
    $('#tabs-help').css({ 'width': '98%', 'height': settings.height });

    if (settings.length == -1)
        $('#pupedit-max').hide();
    else
    {
        $('#pupedit-text').maxlength(settings);
        settings.height -=45;
    }    

//    <div id="tabs-edit" style="width:${wmdWidth-30}px; height: ${wmdHeight-50}px;">
//    $('#tabs-edit').css({ 'width': settings.width+30, 'height': settings.height+50 })
    $('#tabs-edit').css({ 'width': '98%', 'height': settings.height+50 })
                                
    $('#pupedit-text')
         .attr('cols', settings.columns)
         .attr('rows', settings.rows)
//                                .css({ 'width': settings.width, 'height': settings.height })
                                .css({ 'width': '93%', 'height': settings.height })
                                .change(function(evnt)
                                {
                                    target.val($(this).text());
                                });
    $(this).hide();

}